package com.banyuan.servlet.types;

import com.alibaba.fastjson.JSON;
import com.banyuan.dao.TypesDao;
import com.banyuan.domain.ResData;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/types/delete")
public class DeleteServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("id");
        Integer intId = Integer.valueOf(id);
        try {
            int delete = TypesDao.delete(intId);
            if (delete > 0 ) {
                ResData resData = new ResData(200,"删除成功",null);
                resp.getWriter().write(JSON.toJSONString(resData));
            } else {
                ResData resData = new ResData(10001,"删除成功，稍后再试",null);
                resp.getWriter().write(JSON.toJSONString(resData));
            }


        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }



    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
